package cn.edu.neu.softlab633.influencemaximization.sy.bean.CELF;

import cn.edu.neu.softlab633.influencemaximization.sy.bean.Graph;
import cn.edu.neu.softlab633.influencemaximization.sy.model.lt.LinearThresholdModel;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.PriorityQueue;

/**
 * Created by Jason on 2017/5/16.
 */
public class OriginalCELFQueue {
    private PriorityQueue<OriginalCELFQueueEle> originalCELFQueue;

    public OriginalCELFQueue(PriorityQueue<OriginalCELFQueueEle> originalCELFQueue) {
        this.originalCELFQueue = originalCELFQueue;
    }

    public OriginalCELFQueue() {
        originalCELFQueue = new PriorityQueue<>();
    }

    public void initCELFQueue(double threshold, Double[] query, Graph graph) {
        if (originalCELFQueue == null) {
            originalCELFQueue = new PriorityQueue<>();
        }
        Iterator<Integer> iterator = graph.getOutgoingIndex().getIndex().keySet().iterator();
        while (iterator.hasNext()) {
            Integer next = iterator.next();
            ArrayList<Integer> tmp = new ArrayList<>();
            tmp.add(next);
            int influenceSpread = LinearThresholdModel.influencePropagation(threshold, query, tmp, graph).getMarginGainNum();
            originalCELFQueue.add(new OriginalCELFQueueEle(next, influenceSpread, 1));
        }
    }


    public boolean add(OriginalCELFQueueEle ele) {
        return originalCELFQueue.add(ele);
    }

    public OriginalCELFQueueEle peek() {
        return originalCELFQueue.poll();
    }
}
